<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>发表博客</title>
</head>
<body>
<h3>
    写博客
</h3>
<br>
文章标题:<input id="title" type="text">
<br>
文章简介:<input id="des" type="text">
<br>
文章内容:
<br>
<textarea id="content" style="height: 200px ; width: 500px"></textarea>
<br>
<button id="writebtn">发表</button>
</body>

<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>

<script>
    var btn = $("#writebtn");
    var uid;

    btn.click(function () {

        checkCookie();



        $.ajax({
            url:"json/addArtical",
            type:"post",
            data:{
                title: $("#title").val(),
                des: $("#des").val(),
                content: $("#content").val(),
                userId: uid
            },
            success:function (result) {
                if (result.addResult) {
                    window.location.href = "http://localhost:8080/";
                }
            }
        })
    });


    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    function checkCookie() {
        var user = getCookie("name");
        uid = getCookie("userId");


        $("#usernametitle").text("你好:" + user);
    }
</script>
</html>